package com.langChain4j.rag.controller;

import com.base.api.entity.RestResponse;
import com.langChain4j.rag.controller.vo.EmbeddingAppendReqVo;
import com.langChain4j.rag.service.EmbeddingStoreService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author linjun
 * @date 2025/10/11 17:20
 * @description
 */
@RestController
@RequestMapping("/api/v1/embedding")
@Slf4j
@Api(tags = "向量库接口")
public class EmbeddingController {

    @Autowired
    private EmbeddingStoreService embeddingStoreService;

    @PostMapping("appendByUrl")
    @ApiOperation("追加知识库文本")
    public RestResponse<Boolean> appendByUrl(@RequestBody EmbeddingAppendReqVo reqVo) {
        embeddingStoreService.appendByUrl(reqVo.getUrl());
        return RestResponse.<Boolean>builder()
                .data(Boolean.TRUE)
                .build();
    }

    @PostMapping("appendByFile")
    @ApiOperation("追加知识库文本")
    public RestResponse<Boolean> appendByFile(@RequestBody EmbeddingAppendReqVo reqVo) {
        embeddingStoreService.appendByFile(reqVo.getFilePath());
        return RestResponse.<Boolean>builder()
                .data(Boolean.TRUE)
                .build();
    }
}
